<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div{
            width: 150px;
            height: 150px;
            background-color: blueviolet;
        }
    </style>
</head>
<body>
    <div id="div1">
        111
    </div>
    <div id="div2">
        222
    </div>
    <script>
        /* 
            需求：点击div改变他的属性
         */
         const divObj1 = document.querySelector("#div1")
         divObj1.onclick = function(){
             alert("点击了div")
            //  divObj.style.backgroundColor='green'
            //  divObj.style.width="250px"
            //  divObj.style.height="250px"

             //this:当前对象
             this.style.backgroundColor='green'
             this.style.width="250px"
             this.style.height="250px"

         }
         const divObj2 = document.querySelector("#div2")
         divObj2.onclick = function(){
             alert("点击了div")

             //this:当前对象
             this.style.backgroundColor='red'
             this.style.width="250px"
             this.style.height="250px"

         }


         console.dir(divObj)
    </script>
</body>
</html>